var o = getApp();
Page({
    data: {
        opt_id: '',
        dates: '',
        items: [],
        ip: '',
        array: ['全部', '已领取', '未领取'],
        type: ['全部', '得物任务', '抖音任务'],
        time: ['全部', '今天', '昨天'],
        todoList: {},
        time_end: '',
        time_start: '',
        objectArray: [{
            name: '全部'
        },
        {
            name: '已领取'
        },
        {
            name: '未领取'
        },
        ],
        typeList: [{
            name: ''
        },

        ],
        timeList: [{
            name: '全部'
        },
        {
            name: '今天'
        },
        {
            name: '昨天'
        },
        ],
    },
    onLoad(options) {
        this.taskList()
        this.getIP()
        this.setData({
            opt_id: options.id
        })
        this.getList()
    },
    onShow() {
        this.getList()
    },
    getList() {
        console.log('走了吗')
        var t = this, e = o.getNetAddresss("plugin.task-reward.api.quest.questList");
        o._getNetWork({
            url: e,
            data: {
                type: t.data.opt_id
            },
            success: function (a) {
                let arr = a.data.data
                let list = arr.map((item) => {
                    return {
                        ...item,
                        time_cha: item.end * 1000 - Date.parse(new Date())
                    }
                })
                console.log(list, '打印')
                t.setData({
                    items: list,
                })
            }
        });
    },
    //任务分类列表
    taskList() {
        var t = this, e = o.getNetAddresss("plugin.task-reward.api.quest.questType");
        o._getNetWork({
            url: e,
            data: {},
            success: function (a) {
                t.setData({
                    typeList: a.data.data,
                })
                let arr = a.data.data
                let arr1 = []
                arr.forEach((item) => {
                    arr1.push(item.name)
                })
                t.setData({
                    type: arr1,
                })
                console.log(arr1, 'shisha')
            }
        });
    },
    //  点击日期组件确定事件  
    bindDateChange: function (e) {
        console.log(e.detail.value)
        this.setData({
            dates: e.detail.value
        })
        var t = this, e = o.getNetAddresss("plugin.task-reward.api.quest.questList");
        o._getNetWork({
            url: e,
            data: {
                date: t.data.dates
            },
            success: function (a) {
                console.log(a.data.data, '领取状态')
                let arr = a.data.data
                let list = arr.map((item) => {
                    return {
                        ...item,
                        time_cha: item.end * 1000 - Date.parse(new Date())
                    }
                })
                console.log(list, '打印')
                t.setData({
                    items: list,
                })
                // t.setData({
                //     items: a.data.data,
                // })
            }
        });

    },
    //获取ip
    getIP() {
        var t = this, e = o.getNetAddresss("plugin.task-reward.api.quest.getIp");
        o._getNetWork({
            url: e,
            data: {},
            success: function (a) {
                console.log(a.data.data, '打印')
                t.setData({
                    ip: a.data.data,
                })
            }
        });
    },
    onChange(e) {
        let index = e.currentTarget.dataset.index
        let arr = this.data.items
        arr[index].hour = e.detail.days * 24 + e.detail.hours
        arr[index].minutes = e.detail.minutes
        arr[index].seconds = e.detail.seconds
        this.setData({
            items: arr,
        });
    },
    bindtimeList: function (e) {
        this.setData({
            time_class: e.detail.value
        })
    },
    //任务分类
    bindtypeList: function (e) {
        this.setData({
            type_class: e.detail.value
        })
        console.log(e.detail.value)
        let index = e.detail.value
        console.log(this.data.typeList[index].id, this.data.typeList[index].name)

        var t = this, e = o.getNetAddresss("plugin.task-reward.api.quest.questList");
        o._getNetWork({
            url: e,
            data: {
                type: t.data.typeList[index].id
            },
            success: function (a) {
                console.log(a.data.data, '领取状态')
                // t.setData({
                //     items: a.data.data,
                // })
                let arr = a.data.data
                let list = arr.map((item) => {
                    return {
                        ...item,
                        time_cha: item.end * 1000 - Date.parse(new Date())
                    }
                })
                console.log(list, '打印')
                t.setData({
                    items: list,
                })
            }
        });

    },
    //领取状态
    bindPickerChange: function (e) {
        this.setData({
            sell_class: e.detail.value
        })
        console.log(e.detail.value)
        var t = this, e = o.getNetAddresss("plugin.task-reward.api.quest.questList");
        o._getNetWork({
            url: e,
            data: {
                type:'',
                is_draw: t.data.sell_class
            },
            success: function (a) {
                console.log(a.data.data, '领取状态')
                // t.setData({
                //     items: a.data.data,
                // })
                let arr = a.data.data
                let list = arr.map((item) => {
                    return {
                        ...item,
                        time_cha: item.end * 1000 - Date.parse(new Date())
                    }
                })
                console.log(list, '打印')
                t.setData({
                    items: list,
                })
            }
        });
    },
    getTask: function (e) {
        console.log(e.currentTarget.dataset.value)
        wx.navigateTo({
            url: '/packageJ/getaTask/getaTask?id=' + e.currentTarget.dataset.value,
        })
    },
    goback: function () {
        wx.navigateBack({
            delta: 1
        })
    },
    onShareAppMessage() {
        return {};
    },
});